Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
JavaScript: curious to know if "if statements can substitute .include method

I am working on a .filter() method and a given solution has a .include() method in it. I was trying to solve the problem using an inner loop, next I switched to .filter and attempted using an if statement in the inner function.

Below is a code sample:



let arrayOne = [1,2,3,4,5,6];
let arrayTwo = [2,4,6,8,10,'water'];

const filterComparism=(arr1,arr2)=>{
  let newArray=[];
/**return arr1.filter(item=>arr2.includes(item)); this line of Code would solve the issue. is there an alternative step to solve below?
*/
for(let i = 0; i<arr1.length; i++){
  for(let j = 0; j< arr2.length; j++){


    
        newArray.push(arr1===arr2? return true);
  
        }
    }
  return newArray;
}

console.log(filterComparism(arrayOne,arrayTwo));
const filterComparism=(arr1,arr2)=>{ /**return arr1.filter(item=>arr2.includes(item)); this line of Code would solve the issue. is there an alternative step to solve below? */ return arr1.filter(item=>{ if(item===arr2){ return true; } return false; }); }

is there an alternative method to achieve this using an if statement in the inner function or using inner loops to compare values.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda